package com.oasistudio.ads.expert.banner;

import android.app.Activity;
import android.graphics.Color;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.casee.adsdk.CaseeAdView;
import com.casee.adsdk.CaseeAdView.AdListener;
import com.oasistudio.ads.expert.R;


public class AdViewCasee {
	CaseeAdRequestListener adRequestListener;
	Activity activity;
	public static final String UNION = "casee.cn";
	public AdViewCasee(Activity activity){
		this.activity = activity;
		this.adRequestListener = new CaseeAdRequestListener(activity, UNION);
		
		addCaseeAd();
	}
	
	/************************** www.casee.cn start *************************/
	private void addCaseeAd() {
		LinearLayout adContainer = (LinearLayout) activity.findViewById(R.id.ads_container);
		adContainer.addView(new TitleBuilder().createTitle(activity, UNION));

		LinearLayout caseeContainer = new LinearLayout(activity);		
		adContainer.addView(caseeContainer);
		com.casee.adsdk.CaseeAdView cav = new com.casee.adsdk.CaseeAdView(activity, "3490CE14FD0C2A42FB952B68B51A4AEA", false, 10 * 1000, Color.BLACK, Color.WHITE, false);
		cav.setListener(this.adRequestListener);
		caseeContainer.addView(cav, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
	}

	/************************** www.casee.cn end *************************/
	
	class CaseeAdRequestListener extends AbstractAdsExpertAdListener implements AdListener{
		
		public CaseeAdRequestListener(Activity activity, String union){
			super(activity, union);
		}

		@Override
		public void onFailedToReceiveAd(CaseeAdView arg0) {
			// TODO Auto-generated method stub
			this.fail();
		}

		@Override
		public void onFailedToReceiveRefreshAd(CaseeAdView arg0) {
			// TODO Auto-generated method stub
			this.fail();
		}

		@Override
		public void onReceiveAd(CaseeAdView adView) {
			// TODO Auto-generated method stub
			this.succeed();
			AdHistory.saveAd(UNION, adView);
		}

		@Override
		public void onReceiveRefreshAd(CaseeAdView adView) {
			// TODO Auto-generated method stub
			this.succeed();
			AdHistory.saveAd(UNION, adView);
		}
		
	}

}
